/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.xgb.web.rest;

import com.zcm.common.web.BaseController;
import com.zcm.modules.xgb.entity.XgbBoardDown;
import com.zcm.modules.xgb.entity.XgbBoardStock;
import com.zcm.modules.xgb.entity.XgbBoomStock;
import com.zcm.modules.xgb.entity.XgbHistoryData;
import com.zcm.modules.xgb.service.XgbBoardDownService;
import com.zcm.modules.xgb.service.XgbBoardStockService;
import com.zcm.modules.xgb.service.XgbBoomStockService;
import com.zcm.modules.xgb.utils.XgbUtils;
import com.zcm.modules.zhaocai.entity.ZcmKanpanData;
import com.zcm.modules.zhaocai.service.ZcmKanpanDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * 看盘数据Controller
 * @author www
 * @version 2018-04-17
 */
@Controller
@RequestMapping(value = "/rest")
public class XgbRestController extends BaseController {

    @Autowired
    private XgbBoardStockService xgbBoardStockService;
    @Autowired
    private XgbBoomStockService xgbBoomStockService;
    @Autowired
    private XgbBoardDownService xgbBoardDownService;

    @RequestMapping(value = "his")
    @ResponseBody
    public Map his(@RequestParam(value = "symbol")String symbol) {
        List<XgbHistoryData> list = new ArrayList<XgbHistoryData>();
        Map<String,Object> result = new HashMap<String, Object>();
        XgbBoardStock xgbBoardStock = new XgbBoardStock();
        xgbBoardStock.setSymbol(symbol);
        List<XgbBoardStock> xgbBoardStocks = xgbBoardStockService.findList(xgbBoardStock);
        XgbBoomStock xgbBoomStock = new XgbBoomStock();
        xgbBoomStock.setSymbol(symbol);
        List<XgbBoomStock> xgbBoomStocks = xgbBoomStockService.findList(xgbBoomStock);

        XgbBoardDown xgbBoardDown = new XgbBoardDown();
        xgbBoardDown.setSymbol(symbol);
        List<XgbBoardDown> xgbBoardDowns = xgbBoardDownService.findList(xgbBoardDown);

        for (XgbBoardStock bs : xgbBoardStocks ) {
            XgbHistoryData xgbHistoryData = new XgbHistoryData();
            xgbHistoryData.setContinueBoardCount(bs.getContinueBoardCount());
            xgbHistoryData.setDay(bs.getDay());
            xgbHistoryData.setReason(bs.getReason());
            xgbHistoryData.setSymbol(bs.getSymbol());
            xgbHistoryData.setTitle(bs.getTitle());
            xgbHistoryData.setTime(bs.getLastRaiseTime());
            xgbHistoryData.setCurPrice(bs.getCurPrice());
            xgbHistoryData.setPxChangeRate(bs.getPxChangeRate());
            xgbHistoryData.setType("涨停板");
            list.add(xgbHistoryData);
        }

        for (XgbBoomStock bs : xgbBoomStocks ) {
            XgbHistoryData xgbHistoryData = new XgbHistoryData();
            xgbHistoryData.setContinueBoardCount(bs.getContinueBoardCount());
            xgbHistoryData.setDay(bs.getDay());
            xgbHistoryData.setReason(bs.getReason());
            xgbHistoryData.setSymbol(bs.getSymbol());
            xgbHistoryData.setTitle(bs.getTitle());
            xgbHistoryData.setTime(bs.getLastBoomTime());
            xgbHistoryData.setCurPrice(bs.getCurPrice());
            xgbHistoryData.setPxChangeRate(bs.getPxChangeRate());
            xgbHistoryData.setType("被砸开板");
            list.add(xgbHistoryData);
        }


        for (XgbBoardDown bs : xgbBoardDowns ) {
            XgbHistoryData xgbHistoryData = new XgbHistoryData();
            xgbHistoryData.setContinueBoardCount(bs.getContinueBoardCount());
            xgbHistoryData.setDay(bs.getDay());
            xgbHistoryData.setReason(bs.getReason());
            xgbHistoryData.setSymbol(bs.getSymbol());
            xgbHistoryData.setTitle(bs.getTitle());
            xgbHistoryData.setTime(bs.getLastBoardTime());
            xgbHistoryData.setCurPrice(bs.getCurPrice());
            xgbHistoryData.setPxChangeRate(bs.getPxChangeRate());
            xgbHistoryData.setType("跌停板");
            list.add(xgbHistoryData);
        }

        Collections.sort(list, new Comparator<XgbHistoryData>() {
            @Override
            public int compare(XgbHistoryData o1, XgbHistoryData o2) {
                return o1.getDay().compareTo(o2.getDay());
            }
        });

        result.put("ret",true);
        result.put("count",list.size());
        result.put("data",list);
        return result;
    }
}